from formbuild import Form
from formbuild.builder.field import FieldsBuilder
from formbuild.builder import field  
from formbuild.builder import layout  

class MyFields(FieldsBuilder):
    
    type = 'formbuild.builder.field.compound.HtmlFields'

    def recapture_field(self, name, value=None, id=None, error_param='',  **options):
    
        return """<script type="text/javascript" src="%(ApiServer)s/challenge?k=%(PublicKey)s&error=%(ErrorParam)s"></script>
    
    <noscript>
      <iframe src="%(ApiServer)s/noscript?k=%(PublicKey)s&error=%(ErrorParam)s" height="300" width="500" frameborder="0"></iframe><br />
      <textarea name="recaptcha_challenge_field" rows="3" cols="40"></textarea>
      <input type='hidden' name='recaptcha_response_field' value='manual_challenge' />
    </noscript>
    """ % {
            'ApiServer' : 'http://api.recaptcha.net', 
            'PublicKey' : '6Lc8ngAAAAAAAPObJ6TF1fyE5gSzhPydfxCXftRM', 
            'ErrorParam' : error_param, 
            }

    def capture_field(self, name, value=None, id=None, error_param='',  **options):
    
        return """<img src=/captcha/index/> <br/>
            <input  type="text" name="%(name)s"></input>""" % {'name' : name}

class StandardForm(Form):
    field = MyFields(), field.basic.HtmlFields()   
    layout = layout.basic.HtmlLayout() 